import {KeepAliveRpcServerHost, RpcServerHostGroup, StateManagerInMemory} from "dream_rpc";
/**
 Created by:
 muhtearjan mehmood مۇختەرجان مەخمۇت (Email: yeganaaa@163.com)
 At 6/14/20 8:16 AM
 */
import * as Http from "http"
import {MessageBusServer} from "./Core/MessageBusServer";
import {WebSocketServerHost} from "dream_rpc_node_websocket"
import * as WebSocket from "ws"

const webSocketPort = 10000
const tcpSocketPort = 10001

async function main() {
    const httpServer = Http.createServer((request, response) => {
        response.end("Please connect to WebSocket or TcpSocket communication port.")
    });
    httpServer.listen(webSocketPort)
    const server = new MessageBusServer(
        new RpcServerHostGroup([
            new KeepAliveRpcServerHost(new WebSocketServerHost(async () => new WebSocket.Server({path: "/Communication", server: httpServer})), 10 * 1000),
            // new KeepAliveRpcServerHost(new TcpSocketServerHost(async () => Net.createServer(), async tcpServer => {tcpServer.listen(tcpSocketPort)}), 10 * 1000),
        ]),
        new StateManagerInMemory()
    )
    await server.prepareForLaunch()
    await server.launch()

    console.log("Message BUS Server launch successfully")
}

main()

